function Y = process(X, hImgProcess, thresh)
if nargin < 3
    thresh = 9000;
end

ImgNum = size(X, 3);

if ImgNum <= thresh
    Y = squeeze(hImgProcess(X));
    return
end

pp = 0;  cnt = 0;
TotalNum = ceil(ImgNum / thresh);
% hbar = waitbar(0, 'Images are beining processed. Please wait ...');
while pp(end) ~= ImgNum
    cnt = cnt+1;
    fprintf('\tsrimg.process: %d/%d\n', cnt, TotalNum);
%     waitbar(cnt / TotalNum)
    pp = pp(end)+1 : pp(end)+thresh;
    if pp(end) > ImgNum
        pp = pp(1) : ImgNum;
    end
    x = squeeze(hImgProcess(X(:, :, pp)));
    if pp(1) == 1
        s = size(x);
        Y = zeros([s(1:2) ImgNum]);
    end
    Y(:, :, pp) = x;
end
% close(hbar);
